using System;
using System.Web.Mvc;
using HeadspringExample.UI.Helpers;

namespace HeadspringExample.UI.Controllers
{
    public class DefaultController : Controller
    {
        protected XmlResult<T> Xml<T>(T toSerialize)
        {
            return new XmlResult<T>
            {
                ModelToSerialize = toSerialize
            };
        }

        protected AutoMapViewResult AutoMapView<TDestination>(ViewResult viewResult)
        {
            return new AutoMapViewResult(viewResult.ViewData.Model.GetType(), typeof(TDestination), viewResult);
        }

		protected FormActionResult<TForm> Form<TForm>(TForm form, ActionResult success)
		{
			var failure = View(form);

			return new FormActionResult<TForm>(form, success, failure);
		}

    }
}
